<% if @tickets.size > 0 %>
<table border=1>
  <tr>
    <%= (@report_template.selected_main_fields.include? 'name') ? '<th>Name</th>' : "" %>
    <%= (@report_template.selected_main_fields.include? 'number') ? '<th>Number</th>' : "" %>
    <%= (@report_template.selected_main_fields.include? 'created_at') ? '<th>Created at</th>' : "" %>
    <%= (@report_template.selected_main_fields.include? 'deadline') ? '<th>Deadline</th>' : "" %>
    <%= (@report_template.selected_main_fields.include? 'updated_at') ? '<th>Updated at/Closed at</th>' : "" %>
    <%= (@report_template.selected_main_fields.include? 'created_by') ? '<th>Created by</th>' : "" %>
    <%= (@report_template.selected_main_fields.include? 'updated_by') ? '<th>Updated_by/Closed by</th>' : "" %>
    <%= (@report_template.selected_main_fields.include? 'group') ? '<th>Group</th>' : "" %>
    <%= (@report_template.selected_main_fields.include? 'status') ? '<th>Status</th>' : "" %>
    <% @report_template.note_types.each do |note_type|%>
    <th> <%=h note_type.name %> </th>
    <% end %>
  </tr>
  
<% for ticket in @tickets %>
  <%= ticket.status ? "<tr bgcolor='green'>" : (ticket.deadline < Date.today ? "<tr bgcolor='red'>" : "<tr bgcolor='yellow'>")  %>
  
    <% if @report_template.selected_main_fields.include? 'name' %><td><%= ticket.name%></td> <% end %>
    <% if @report_template.selected_main_fields.include? 'number' %><td><%= ticket.number %></td> <% end %>
    <% if @report_template.selected_main_fields.include? 'created_at' %><td><%= ticket.created_at.to_date %></td> <% end %>
    <% if @report_template.selected_main_fields.include? 'deadline' %><td><%= ticket.deadline %></td><% end %>
    <% if @report_template.selected_main_fields.include? 'updated_at' %><td><%= ticket.updated_at.to_date %></td> <% end %>
    <% if @report_template.selected_main_fields.include? 'created_by' %><td><%=h ticket.created_by ? ticket.created_by.name : "somebody"%></td><% end %>
    <% if @report_template.selected_main_fields.include? 'updated_by' %><td><%=h ticket.updated_by ? ticket.updated_by.name : "somebody"%></td><% end %>
    <% if @report_template.selected_main_fields.include? 'group' %><td><%=h ticket.group ? ticket.group.name : "ticket is closed"%></td><% end %>
    <% if @report_template.selected_main_fields.include? 'status' %><td><%=h (ticket.group == 0) ? "closed" : "open"%></td><% end %>
    <% @report_template.note_types.each do |note_type|%>
       <td> <%=h ticket.notes[note_type.priority].value %> </td>
    <% end %>


    <td>  <%= link_to "Show", ticket_path(ticket) %> </td>
    <% if current_user.admin? %>
      <td><%= link_to "Destroy", ticket_path(ticket), :method => :delete, :confirm => "Are you sure?" %></td>
    <% end %>
  </tr>
<% end if @tickets%>
</table>
<% end %>

